package com.yg.base.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yg.base.mapper.ImageMapper;
import com.yg.base.pojo.Image;
import com.yg.base.pojo.vo.BannerVo;
import com.yg.base.pojo.vo.Item;
import com.yg.base.service.ImageService;
import com.yg.base.feign.ItemFeignService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 图片表 服务实现类
 * </p>
 *
 * @author 魏成龙
 * @since 2020-11-07
 */
@Service
public class ImageServiceImpl extends ServiceImpl<ImageMapper, Image> implements ImageService {

    @Autowired
    private ItemFeignService itemFeignService;
    /**
     * 查询所有轮播图
     * @return
     */
    @Override
    public List findAllBanner() {
        //轮播图 type = 1

        QueryWrapper<Image> imageQueryWrapper = new QueryWrapper<>();
        imageQueryWrapper.eq("type",1);
        List<Image> images = baseMapper.selectList(imageQueryWrapper);
        List list = new ArrayList();
        //item(多) -> image(1)
        for (int i = 0; i < images.size(); i++) {
            Image image = images.get(i);
            Integer targetId = image.getTargetId();
            Item item = itemFeignService.getItemById(targetId);
            BannerVo bannerVo = new BannerVo();
            bannerVo.setId(image.getId());
            bannerVo.setImaUrl(image.getImgUrl());
            bannerVo.setItemName(item.getItemName());
            bannerVo.setMinPrice(item.getMinPrice());

            list.add(bannerVo);
        }
        return list ;
    }


}
